package com.example.swaggerproject.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "统一返回结果")
public class Result<T> {

    @Schema(description = "返回结果状态码", example = "200")
    private Integer code;

    @Schema(description = "返回结果信息", example = "成功")
    private String message;

    @Schema(description = "返回结果数据")
    private T data;

    @Schema(description = "返回结果成功")
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }

    @Schema(description = "返回结果失败")
    public static <T> Result<T> error(String message) {
        return new Result<>(500, message, null);
    }

}
